let currLat = 113.812223
let currLng = 34.797118

let subwayLocationList = [
  { lat: 113.819412, lng: 34.826345, name: "河南大学新区站" },
  { lat: 113.818827, lng: 34.814363, name: "文苑北路站" },
  { lat: 113.817104, lng: 34.798464, name: "龙子湖站" },
  { lat: 113.817037, lng: 34.778621, name: "市体育中心站" },
  { lat: 113.799026, lng: 34.765833, name: "博学路站" },
]

let nearestDistance = Number.MAX_SAFE_INTEGER
let nearestStation = -1
let nearestThreeStation = new Array(3).fill({
  lat: Number.MAX_SAFE_INTEGER,
  lng: Number.MAX_SAFE_INTEGER,
})
const distanceBetween = ({ lat, lng }) => Math.hypot(lat - currLat, lng - currLng)

subwayLocationList.forEach((v, i) => {
  let distance = distanceBetween(v)
  if (distance < nearestDistance) {
    nearestDistance = distance
    nearestStation = i
  }

  if (distance < distanceBetween(nearestThreeStation[0])) {
    ;[nearestThreeStation[0], nearestThreeStation[1]] = [v, nearestThreeStation[0]]
  } else if (distance < distanceBetween(nearestThreeStation[1])) {
    ;[nearestThreeStation[1], nearestThreeStation[2]] = [v, nearestThreeStation[1]]
  } else if (distance < distanceBetween(nearestThreeStation[2])) {
    nearestThreeStation[2] = v
  }
})

console.log(subwayLocationList[nearestStation].name)

console.log(nearestThreeStation.map(v => v.name))
